import Vue from'vue'
import store from '@/store/store'

Vue.filter('filterDate', function(date) {
  if (!date) return
  let time = parseInt(date.split('__DATE__')[1])
  return new Date(time).format('yyyy-MM-dd')
})

Vue.filter('filterDateAll', function(date) {
  if (!date) return
  let time = parseInt(date.split('__DATE__')[1])
  return new Date(time).format('yyyy-MM-dd hh:mm:ss')
})

Vue.filter('filterNoticeType', function (type) {
  switch (type) {
    case 1:
      return 'danger'
      break;
    case 2:
      return 'success'
      break;
    case 3:
      return 'success'
      break;
    case 4:
      return 'warning'
      break;
  }
})

Vue.filter('filterSampleType', function (type) {
  switch (type) {
    case 1:
      return '设置上下架'
      break;
    case 2:
      return '设置新品'
      break;
    case 3:
      return '设置推荐'
      break;
    case 4:
      return '入库操作'
      break;
    case 5:
      return '出库操作'
      break;
    case 6:
      return '货架号修改'
      break;
    case 7:
      return '设置热门'
      break;
  }
})

Vue.filter('filterUrl', function(url) {
  let host = window.location.hostname === '123.58.39.242' || window.location.hostname === '192.168.2.71' ? 'https://ja-material-formal.oss-cn-shenzhen.aliyuncs.com' : 'https://ja-material-test.oss-cn-shenzhen.aliyuncs.com'
  if (!url) return
  if (url.indexOf('http') >= 0 || url.indexOf('https') >= 0) return { 'backgroundImage': `url(${url})` }
  else return { 'backgroundImage': `url(${host}${url})` }
})
Vue.filter('filterSrc', function(url) {
  let host = window.location.hostname === '123.58.39.242' || window.location.hostname === '192.168.2.71' ? 'https://ja-material-formal.oss-cn-shenzhen.aliyuncs.com' : 'https://ja-material-test.oss-cn-shenzhen.aliyuncs.com'
  if (!url) return
  if (url.indexOf('http') >= 0 || url.indexOf('https') >= 0) return url
  else return `${host}${url}`
})

Vue.filter('filterSupplier', function (type) {
  switch (type) {
    case 1:
      return '国企'
      break;
    case 2:
      return '股份制'
      break;
    case 3:
      return '私企/集体'
      break;
    case 4:
      return '中外合资'
      break;
    case 5:
      return '外商独资'
      break;
    case 6:
      return '其他'
      break;
    default:
      return '/'
  }
})

Vue.filter('filterPermission', function (val) {
  let valid = store.state.user.user.permissionList.some(item => item === val)
  return valid ? '' : 'permission-hide'
})
